/**
 * @param {ListNode} head
 * @return {boolean}
 */
var isPalindrome = function (head) {
  //1. 找到链表的中点
  let slow = head, fast = head
  while (fast && fast.next) {
    slow = slow.next
    fast = fast.next.next
  }
  //2. 如果链表节点个数为奇数，slow指针后移一位
  if (fast) {
    slow = slow.next
  }
  //3. 将链表的后半部分翻转（难点：要理解，并快速记忆！）
  let prev = null
  while (slow) {
    let temp = slow.next
    slow.next = prev
    prev = slow
    slow = temp
  }
  //4. 逐个进行比对
  let left = head
  let right = prev
  while (right) {//right节点更少，把它作为循环条件
    if (left.val !== right.val) {
      return false
    }
    left = left.next
    right = right.next
  }

  return true
};